package com.hzhc.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzhc.entity.SysYzsRole;
import com.hzhc.mapper.SysYzsRoleMapper;
import com.hzhc.service.SysYzsRoleService;
import com.hzhc.vo.SysYzsRoleVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dongcy
 * @date 2024/4/10 9:34
 * @description SysYzsRoleServiceImpl
 */
@Service
@RequiredArgsConstructor
public class SysYzsRoleServiceImpl extends ServiceImpl<SysYzsRoleMapper, SysYzsRole> implements SysYzsRoleService {

    private final SysYzsRoleMapper sysYzsRoleMapper;

    @Override
    public List<SysYzsRoleVo> getYzsRoleJsonPage(Page<SysYzsRoleVo> page, SysYzsRoleVo vo) {

        return baseMapper.selectYzsRolePageJson(page,vo).getRecords();
    }

    @Override
    public List<SysYzsRole> getRoleList(SysYzsRole yzsRole) {
        QueryWrapper<SysYzsRole> queryWrapper = new QueryWrapper<SysYzsRole>();
        if(StrUtil.isNotBlank(yzsRole.getName())){
            queryWrapper.like("name",yzsRole.getName());
        }
        return sysYzsRoleMapper.selectList(queryWrapper);
    }

    @Override
    public List<SysYzsRole> getPageRole(Page<SysYzsRole> page, String searchdata) {
        QueryWrapper<SysYzsRole> queryWrapper = new QueryWrapper<SysYzsRole>();
        if (StrUtil.isNotBlank(searchdata)) {
            queryWrapper.like("name", searchdata);
        }
        Page<SysYzsRole> retrolemap = sysYzsRoleMapper.selectPage(page, queryWrapper);
        return retrolemap.getRecords();
    }

    @Override
    public Boolean saveRole(SysYzsRole datas) {
        return save(datas);
    }

    @Override
    public Boolean updateRole(SysYzsRole datas) {
        return updateById(datas);
    }

    @Override
    public Boolean delRole(Long id) {
        int bol = sysYzsRoleMapper.deleteById(id);
        return bol == 1;
    }
}
